<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #wenzi {
            color: red;
        }

        #result {
            width: 800px;
            height: 100px;
            border: 1px solid springgreen;
            margin-top: 10px;
        }

        #spen {
            color: rgb(245, 60, 60);
        }

        #c {
            width: 800px;
            height: 150px;
        }
    </style>
    <script>
        window.onload = function () {
            var input_element = document.getElementsByTagName("input");
            input_element[2].onclick = function () {
                var n = parseFloat(input_element[0].value);
                var k = parseFloat(input_element[1].value);
                var str = "";
                var sum = 0;
                for (var i = 1; i <= n; i++) {
                    var a = 1;//a是次方的结果，初值为1；
                    for (var j = 1; j <= k; j++) {
                        a = a * i;
                    }
                    if (i == n) {
                        str = str + i + "^" + k + "<span class='colorblue'>=</span>";
                    } else {
                        str = str + i + "^" + k + "<span>+</span>";
                    }
                    sum = sum + a;

                }
                document.getElementById("result").innerHTML = str + sum;

            }

        }
    </script>
</head>

<body>
    <h2>求次方和</h2>
    <form action="">
        <bdi id="wenzi"> 请输入n和k的值，然后单击计算按钮：</bdi>
        <input type="text" name="" id="" placeholder="请输入n">
        <input type="text" name="" id="" placeholder="请输入k">
        <input type="button" value="计算">


    </form>
    <div id="spen"></div>
    <div id="result"></div>
</body>

</html>